<?php 
	$data['menu'] = 'acl';
	$data['title'] = '权限模块';
//	$data['jses'] = array('js/manager/acl.js');
	$this->load->view('manager/header',$data);
?>
<div class="crumbs">当前位置：<a href="#">权限管理</a> &gt; <span class="silver">权限模块</span></div>
<?php if(isset($message)){?>
<div class="tip tip-b">
    <p class="alert noclose"><i class="icon"></i><?php echo $message;?></p>				
</div>
<?php }?>
<div class="list-tab">
	<ul>
		<li <?php if($action == 'list') echo 'class="cur"'?>><a href="<?php echo site_url('manager/acl/module');?>">功能模块</a></li>
		<li <?php if($action == 'add') echo 'class="cur"'?> title="新增模块"><a href="<?php echo site_url('manager/acl/module/add');?>" title="新增模块">新增模块</a></li>
		<?php if($action == 'edit') 
			echo '<li class="cur" title="编辑模块">编辑模块</li>';
		?>
	</ul>
</div>
<?php if($action == 'list'){?>
<table class="list-table list-table-s">
	<thead>
		<tr>
			<th align="left" width="100">模块名称</th>
			<th align="left" width="100">操作</th>
			<th align="left" width="100">模块名称</th>
			<th align="left" width="100">操作</th>
			<th align="left" width="100">模块名称</th>
			<th align="left" width="100">操作</th>
		</tr>
	</thead>
	<tbody>
	<?php
		if(isset($list) && count($list)){
			$i = 0;
	?>
		<tr>
		<?php 
			foreach ($list as $item) {
				if($i != 0 && $i % 3 == 0){
		?>
		</tr><tr>
		<?php }$i++;?>
			<td align="left" width="100"><?php echo $item['name'];?></td>
			<td align="left" width="100">
				<a href="<?php echo site_url('manager/acl/module/edit/'),'/',$item['mid'];?>">编辑</a>
				<?php if($item['pnum'] == 0){?>
				/ <a href="<?php echo site_url('manager/acl/module/dodelete/'),'/',$item['mid'];?>">删除</a>
				<?php }?>
			</td>
	<?php }}else{?>	
			<td colspan="6" align="center">	
				对不起，暂无数据！
			</td>
	<?php }?>
		</tr>
	</tbody>
</table>
<?php $this->load->view('pager');?>
<?php }else if($action == 'add' || $action == 'edit'){
	$hasPermissions = isset($permissions) && count($permissions);
?>
<script>
	$(function($){
		new plugor.form('acl_module');
		$('a.delete_tmp').live('click',function(){
			var pid = $(this).prev().val();
			if(+pid){
				$(this).parents('tr').find('input').css('background','#ccc').attr('readonly','true').attr('name',function(i,elem){return 'tmp_'+elem;});
				$(this).replaceWith('<a class="cancel_tmp" style="color:red;">取消<input type=hidden value='+pid+' name=pid[] /></a>')
			}else{
				$(this).parents('tr').remove();
			}
		});
		$('a.cancel_tmp').live('click',function(){
			$(this).parents('tr').find('input').removeAttr('style').removeAttr('readonly').attr('name',function(i,elem){return elem.substring(4);});
			$(this).replaceWith('<a class="delete_tmp">删除</a>');
		});
	});
</script>
<table class="hidden">
	<tr id="template" num="<?php echo $hasPermissions?count($permissions):1;?>">
		<td align="left" width="100"><input type="text" name="permission[%d][name]" valid="required|realname"/></td>
		<td align="left"><input type="text" name="permission[%d][url]" size="50" valid="required|url"/></td>
		<td align="left" width="70"><input type="text" name="permission[%d][sort]" size="1" valid="integer"/></td>
		<td align="center" width="100"><input type="hidden" name="permission[%d][pid]" value="0"/><a class="delete_tmp">删除</a></td>
	</tr>
</table>
<form id="acl_module" action="<?php echo site_url('manager/acl/module/do'.$action.'/');?>" method="post">
	<table class="list-table list-table-s form5">
		<thead>
			<tr>
				<th colspan="4" align="left" height="35">
					<?php if($action == 'edit'){?>
						<input type="hidden" name="module[mid]" value="<?php if(isset($module)) echo $module['mid']?>" />
					<?php }?>
					<span class="red">* </span>名称：<input valid="required|realname|is_exist:<?php if(isset($module)) echo $module['name'].'@';echo site_url('manager/acl/module/isExistName')?>" id="module_name" name="module[name]" type="text" value="<?php if(isset($module)) echo $module['name']?>"/>
					<div id="module_name_tip"></div>
				</th>
			</tr>
			<tr>
				<th colspan="4" align="left" height="35">
					&nbsp;&nbsp; 排序：<input valid="integer" name="module[sort]" type="text" value="<?php if(isset($module)) echo $module['sort']?>"/>
				</th>
			</tr>
			<tr>
				<th align="left" width="100"><span class="red">* </span>权限名称</th>
				<th align="left"><span class="red">* </span>URL路径</th>
				<th align="left" width="70">排序</th>
				<th align="center" width="100">操作<a class="jstemplate" href="#f=template&t=permissionTbody">[<b>+</b>]</a></th>
			</tr>
		</thead>
		<tbody id="permissionTbody">
		<?php 
		if($hasPermissions){
			$i = 0;
			foreach ($permissions as $item) {
		?>
			<tr>
				<td align="left" width="100"><input type="text" name="permission[<?php echo $i;?>][name]" value="<?php echo $item['name']?>"  valid="required|realname"/></td>
				<td align="left"><input type="text" name="permission[<?php echo $i;?>][url]" size="50" value="<?php echo $item['url']?>"  valid="required|url"/></td>
				<td align="left" width="70"><input type="text" name="permission[<?php echo $i;?>][sort]" size="1" value="<?php echo $item['sort']?>"  valid="integer"/></td>
				<td align="center" width="100"><input type="hidden" name="permission[<?php echo $i;?>][pid]" value="<?php echo $item['pid']?>"/><a class="delete_tmp">删除</a></td>
			</tr>
		<?php $i++; }}else{?>
			<tr>
				<td align="left" width="100"><input type="text" name="permission[0][name]" valid="required|realname"/></td>
				<td align="left"><input type="text" name="permission[0][url]" size="50" valid="required|url"/></td>
				<td align="left" width="70"><input type="text" name="permission[0][sort]" size="1" valid="integer"/></td>
				<td align="center" width="100"><input type="hidden" name="permission[0][pid]" value="0"/><a class="delete_tmp">删除</a></td>
			</tr>
		<?php }?>
		</tbody>
		<tfoot>
			<tr>
				<th colspan="4" align="center" height="35">
					<input type="button" value="提交" ajax="true"/>
				</th>
			</tr>
		</tfoot>
	</table>
</form>
<?php }?>
<?php $this->load->view('manager/footer');?>